package com.lwy.qiuchao.vending.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.lwy.qiuchao.vending.vo.SkuinfoVo;
import com.lwy.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lwy.qiuchao.vending.entity.VendingSkuEntity;
import com.lwy.qiuchao.vending.service.VendingSkuService;
import com.lwy.common.utils.PageUtils;


/**
 * 
 *
 * @author lwy
 * @email ${email}
 * @date 2020-12-01 15:51:09
 */
@RestController
@RequestMapping("vending/vendingsku")
public class VendingSkuController {
    @Autowired
    private VendingSkuService vendingSkuService;

    /**
     * 通过球场id和贩卖机id查询 该贩卖机所有的sku信息
     * */
    @RequestMapping("/listdetail")
    public R listdetail(@RequestParam Map<String,Object> params){
        List<SkuinfoVo> vos = vendingSkuService.listdetail(params);
        return R.ok().put("data",vos);
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = vendingSkuService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{vId}")
    public R info(@PathVariable("vId") Long vId){
		VendingSkuEntity vendingSku = vendingSkuService.getById(vId);

        return R.ok().put("vendingSku", vendingSku);
    }

    /**
     * 贩卖机上架商品
     */
    @RequestMapping("/save")
    public R save(@RequestBody VendingSkuEntity vendingSku){
        R r = vendingSkuService.saveVending(vendingSku);
        return r;
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody VendingSkuEntity vendingSku){
		vendingSkuService.updateById(vendingSku);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] vIds){
		vendingSkuService.removeByIds(Arrays.asList(vIds));

        return R.ok();
    }

}
